package com.zzjson.crud.service;

import com.zzjson.crud.bean.Employee;
import com.zzjson.crud.dao.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.crud.service</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年07月09日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@Service
public class EmployeeService {
	@Autowired
	EmployeeMapper employeeMapper;

	public List<Employee> getAll() {

		return employeeMapper.selectByMap(null);
	}

	public void saveEmpsInfo(Employee employee) {
		employeeMapper.insertSelective(employee);
	}

	//检查用户名
	public boolean cheUser(String empName) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("empName", empName);

		long count = employeeMapper.countByMap(map);
		return count == 0;
	}

	//按id查询
	public Employee getEmp(Integer id) {
		Employee employee = employeeMapper.selectByPrimaryKey(id);
		return employee;
	}

	//员工更新
	public void updateEmp(Employee employee) {
		employeeMapper.updateByPrimaryKeySelective(employee);
	}

	public void deleteEmp(Integer id) {
		employeeMapper.deleteByPrimaryKey(id);
	}

	public void deleteBatch(List<Integer> ids) {
		employeeMapper.deleteByList(ids);

	}
}